package com.lagou.handler;

import java.sql.Time;
import java.sql.Timestamp;
import java.time.*;
import java.time.chrono.JapaneseDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 类型处理器
 * @author zhengzc
 * @version 1.0.0
 * @date 2020/2/25 00:41
 */
public final class TypeHandlerRegistry {
    private final Map<Class<?>, Boolean> allTypeHandlersMap = new HashMap();
    public TypeHandlerRegistry() {
        this.register(Boolean.class, true);
        this.register(Boolean.TYPE, true);
        this.register(Byte.class, true);
        this.register(Byte.TYPE, true);
        this.register(Short.class, true);
        this.register(Short.TYPE, true);
        this.register(Integer.class,true);
        this.register(Integer.TYPE, true);
        this.register(Long.class, true);
        this.register(Long.TYPE, true);
        this.register(Float.class, true);
        this.register(Float.TYPE, true);
        this.register(Double.class, true);
        this.register(Double.TYPE, true);
        this.register(String.class, true);
        this.register( Date.class,true);
        this.register(java.sql.Date.class, true);
        this.register( Time.class, true);
        this.register( Timestamp.class, true);
        this.register(Instant.class, true);
        this.register(LocalDateTime.class, true);
        this.register(LocalDate.class, true);
        this.register(LocalTime.class, true);
        this.register(OffsetDateTime.class, true);
        this.register(OffsetTime.class, true);
        this.register(ZonedDateTime.class, true);
        this.register(Month.class, true);
        this.register(Year.class, true);
        this.register(YearMonth.class, true);
        this.register(JapaneseDate.class, true);
        this.register(Character.class, true);
        this.register(Character.TYPE, true);
    }

    private void register(Class aClass, boolean b) {
        allTypeHandlersMap.put(aClass,b);
    }

    public Map<Class<?>, Boolean> getAllTypeHandlersMap() {
        return allTypeHandlersMap;
    }

    public boolean isBasicType(Class aClass){
        if (allTypeHandlersMap.containsKey(aClass)){
            return allTypeHandlersMap.get(aClass);
        } else {
            return false;
        }
    }
}
